/*
 *  Copyright (c) 2011 Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the GNU Lesser Public License v2.1
 *  which accompanies this distribution, and is available at
 *  http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 *
 *  Contributors:
 *      Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany - RMI Server and wrapper
 */
package de.ipk_gatersleben.bit.bi.edal.rmi.interfaces;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.security.Principal;
import java.util.List;
import java.util.Map;

import javax.security.auth.Subject;

import de.ipk_gatersleben.bit.bi.edal.aspectj.security.GrantableMethods.Methods;
import de.ipk_gatersleben.bit.bi.edal.primary_data.file.PrimaryDataDirectoryException;
import de.ipk_gatersleben.bit.bi.edal.primary_data.file.EdalException;
import de.ipk_gatersleben.bit.bi.edal.primary_data.metadata.MetaData;
import de.ipk_gatersleben.bit.bi.edal.primary_data.security.EdalAuthenticateException;
import de.ipk_gatersleben.bit.bi.edal.rmi.server.Authentication;

/**
 * RMI Interface for
 * {@link de.ipk_gatersleben.bit.bi.edal.primary_data.DataManager} objects.
 * 
 * @author arendd
 */
public interface DataManagerRmiInterface extends Remote {

	Subject authenticate(Authentication authentication) throws RemoteException,
			EdalAuthenticateException;

	/**
	 * {@link de.ipk_gatersleben.bit.bi.edal.primary_data.file.ImplementationProvider#shutdown()}
	 * 
	 * @return a new {@link MetaData} object.
	 * @throws RemoteException
	 *             if unable to call remote function.
	 * @see de.ipk_gatersleben.bit.bi.edal.primary_data.file.ImplementationProvider#createMetaDataInstance()
	 */
	MetaData createMetaDataInstance() throws RemoteException;

	/**
	 * {@link de.ipk_gatersleben.bit.bi.edal.primary_data.DataManager#getAvailableStorageSpace()}
	 * 
	 * @return available space
	 * @throws RemoteException
	 *             if unable to call remote function.
	 * @throws EdalException
	 *             if no mount path is set.
	 * 
	 * @see de.ipk_gatersleben.bit.bi.edal.primary_data.DataManager#getAvailableStorageSpace()
	 */
	Long getAvailableStorageSpace() throws RemoteException, EdalException;

	/**
	 * {@link de.ipk_gatersleben.bit.bi.edal.primary_data.DataManager#getDefaultPermissions()}
	 * 
	 * @return map with all default permissions.
	 * @throws RemoteException
	 *             if unable to call remote function.
	 * @see de.ipk_gatersleben.bit.bi.edal.primary_data.DataManager#getDefaultPermissions()
	 */
	Map<Principal, List<Methods>> getDefaultPermissions()
			throws RemoteException;

	/**
	 * {@link de.ipk_gatersleben.bit.bi.edal.primary_data.DataManager#getRootDirectory(de.ipk_gatersleben.bit.bi.edal.primary_data.file.ImplementationProvider, Subject)}
	 * 
	 * @param subject
	 *            the authenticated subject
	 * @return the root
	 *         {@link de.ipk_gatersleben.bit.bi.edal.primary_data.file.PrimaryDataDirectory}
	 *         for the passed implementation
	 * @throws RemoteException
	 *             if unable to call remote function.
	 * @throws PrimaryDataDirectoryException
	 *             if any.
	 * @see de.ipk_gatersleben.bit.bi.edal.primary_data.DataManager#getRootDirectory(de.ipk_gatersleben.bit.bi.edal.primary_data.file.ImplementationProvider,
	 *      Subject)
	 */
	PrimaryDataDirectoryRmiInterface getRootDirectory(final Subject subject)
			throws RemoteException, PrimaryDataDirectoryException;

	/**
	 * Getter all supported {@link Principal}s of the current eDAL system.
	 * 
	 * @return the list of supported {@link Principal}s
	 * @throws RemoteException
	 *             if unable to call remote function.
	 * @throws EdalException
	 *             if unable to load {@link Principal}s.
	 */
	List<Class<? extends Principal>> getSupportedPrincipals()
			throws RemoteException, EdalException;

	/**
	 * {@link de.ipk_gatersleben.bit.bi.edal.primary_data.DataManager#getUsedStorageSpace()}
	 * 
	 * @return used space
	 * @throws RemoteException
	 *             if unable to call remote function.
	 * @throws EdalException
	 *             if no mount path is set.
	 * @see de.ipk_gatersleben.bit.bi.edal.primary_data.DataManager#getAvailableStorageSpace()
	 */
	Long getUsedStorageSpace() throws RemoteException, EdalException;

	/**
	 * {@link de.ipk_gatersleben.bit.bi.edal.primary_data.file.ImplementationProvider#shutdown()}
	 * 
	 * @throws RemoteException
	 *             if unable to call remote function.
	 * @see de.ipk_gatersleben.bit.bi.edal.primary_data.file.ImplementationProvider#shutdown()
	 */
	void shutdown() throws RemoteException;
}